/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.upn.sigemfi.sac.bc;

import edu.upn.sigemfi.sac.be.ParametroScoring;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author GABRIEL
 */
public class ParametroScoringDelegate {

    private ParametroScoringFacadeLocal local;

    public ParametroScoringDelegate() {
        local = lookupParametroScoringFacade();
    }

    private ParametroScoringFacadeLocal lookupParametroScoringFacade() {
        try {
            Context c = new InitialContext();
            return (ParametroScoringFacadeLocal) c.lookup("java:comp/env/ParametroScoringFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    public void crear(ParametroScoring par) throws Exception{
        try {
            local.create(par);
        } catch (Exception ex){
            local = lookupParametroScoringFacade();
            throw new Exception("Crear Parametro Scoring... " + ex.getMessage());
        }
    }

    public void editar(ParametroScoring par) throws Exception{
        try {
            local.edit(par);
        } catch (Exception ex){
            local = lookupParametroScoringFacade();
            throw new Exception("Editar Parametro Scoring... " + ex.getMessage());
        }
    }

    public void eliminar(ParametroScoring par) throws Exception{
        try {
            local.remove(par);
        } catch (Exception ex){
            local = lookupParametroScoringFacade();
            throw new Exception("Eliminar Parametro Scoring... " + ex.getMessage());
        }
    }

    public List<ParametroScoring> todos() throws Exception{
        List<ParametroScoring> all = null;

        try {
            all = local.findAll();
        } catch (Exception ex){
            local = lookupParametroScoringFacade();
            throw new Exception("Listar Parametro Scoring... " + ex.getMessage());
        }

        return all;
    }

}
